package com.hisense.ovcloud.warehouse.amq;

import com.hisense.ovcloud.commons.configs.activemq.AMQProps;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.core.JmsTemplate;

import javax.jms.Topic;

@Configuration
public class AMQProducerConfig {
    public AMQProducerConfig(AMQProps amqConfig) {
        this.amqConf = amqConfig;
    }

    @Bean
    public Topic blackListTopic() {
        return new ActiveMQTopic("WGNS_BLACK_LIST");
    }

    private final AMQProps amqConf;

    @Bean
    @Qualifier("blackListJmsTemplate")
    public JmsTemplate blackListJmsTemplate() {
        JmsTemplate template = new JmsTemplate();
        template.setDefaultDestination(blackListTopic());
        template.setConnectionFactory(new ActiveMQConnectionFactory(amqConf.getUsername(), amqConf.getPassword(), amqConf.getBrokerUrl()));
        return template;
    }
}
